﻿using Npgsql;
using System;
using System.Data;

namespace EOrm.NpgsqlProvider
{
    /// <summary>
    /// 构建postgres数据库填充器接口
    /// </summary>
    public class PgAdapterCreator : IDbAdapterCreator
    {
        /// <summary>
        /// 构建postgres数据库填充器
        /// </summary>
        /// <param name="cmd">postgres数据库命令</param>
        /// <returns>postgres数据库填充器</returns>
        public IDbDataAdapter Create(IDbCommand cmd)
        {
            if (cmd==null)
            {
                throw new ArgumentNullException("cmd", "数据库命令对象为空");
            }
            NpgsqlCommand pgCmd = cmd as NpgsqlCommand;
            if (pgCmd==null)
            {
                throw new Exception("向postgres数据库命令转换失败");
            }
            NpgsqlDataAdapter res = new NpgsqlDataAdapter(pgCmd);
            return res;
        }
    }
}
